﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AdvCMS.Data.Linq;
// Created By AdvGen
// URL : http://www.itblogs.info
// URL : http://www.advgen.com
// Lifestyle News in Brisbane - http://www.liveinbne.info
namespace AdvCMS.Data.Repositories
{
    public class UserRepository :IUserRepository
    {
        public AdvCMS.Data.Linq.UsersDataContext DataContext { get; set; }
        public IAdvUser Create()
        {
            return new AdvUser();
        }

        public IList<IAdvUser> FindAll()
        {
            return DataContext.AdvUsers.ToList<IAdvUser>();
        }

        public IAdvUser Get(int id)
        {
            return DataContext.AdvUsers.FirstOrDefault(x => x.Id == id);
        }

        public IAdvUser GetByUserName(string username)
        {
            return DataContext.AdvUsers.FirstOrDefault(x => x.Username == username);
        }

        public void Insert(IAdvUser user)
        {
            DataContext.AdvUsers.InsertOnSubmit((AdvUser)user);
        }


        public void Delete(IAdvUser user)
        {
            DataContext.AdvUsers.DeleteOnSubmit((AdvUser)user);
        }


        public void Update()
        {
            DataContext.SubmitChanges();
        }
    }
}
